package coms.process;


import java.util.Map;
import org.slf4j.LoggerFactory;
import com.beans.CategoryBean;
import com.beans.CompanyBean;
import com.beans.GroupBasicBean;
import com.beans.ORGBean;
import com.crc.mam.BaseCase;
import coms.AutoException;
import coms.Constants;
import frame.FrameWork;
import frame.InterTest;
import functions.ems_accountant_job_pool.AccountGroupWork;
import functions.ems_accountant_job_pool.Group;
import functions.ems_base_data.Category;
import functions.mams_rest.Org;

/**
 * 添加小组工作范围 
 * @author CHENHAILIAN6
 *
 */
public class AddGroupWorkProcess extends BaseCase implements InterTest{
  private org.slf4j.Logger logger = LoggerFactory.getLogger(AddGroupWorkProcess.class);
  String groupName;
  String groupId;
  
  public String getGroupName() {
    return groupName;
  }

  public void setGroupName(String groupName) {
    this.groupName = groupName;
  }

  public String getGroupId() {
    return groupId;
  }

  public void setGroupId(String groupId) {
    this.groupId = groupId;
  }


  /**
   * 入参：groupName，groupType，categoryCode，categoryName，deptBean
   * useFlay (可不填，默认为0),rateValue(可不填，默认为"")
   */
  @Override
  public void run(Map<Object, Object> paramMap) {
    String baseUrl = (String) paramMap.get("baseUrl");
    if(baseUrl !=null) {
      FrameWork.setBaseUrl(baseUrl);
    }
      LoginTest loginTest = new LoginTest();
      loginTest.run(paramMap);
  
      if(!loginTest.status) {
        remark = loginTest.result;
        status = false;
        throw new AutoException("登录失败，阻碍测试");
      }
    groupName = (String) paramMap.get("groupName");
    String groupType = (String) paramMap.get("groupType");
    Group group = new Group();
    GroupBasicBean groupBaseBean = group.findByNameOrType(groupType, groupName);
    groupId = groupBaseBean.getGroupId();
    Category category = new Category();
    String categoryCode = (String) paramMap.get("categoryCode");
    String categoryName = (String) paramMap.get("categoryName");
   
   /* CategoryBean categoryBean = null;
    categoryBean = new CategoryBean("", "", "", "", "", "", "", "", "");*/
    CategoryBean categoryBean = null;
    if(categoryCode == null) {
      categoryBean = new CategoryBean("", "", "", "", "", "", "", "", "");
    }else {
      category.findCategoryByCategoryCode(categoryCode);
      categoryBean =  category.getCategoryByName(categoryName);
      logger.info("工作组设置 业务类型： " + categoryBean.toString());
    }
    ORGBean deptBean = (ORGBean) paramMap.get("deptBean");
   
    if(deptBean == null) {
      deptBean = new ORGBean("", "", "", null, "", "", "");
    }
    logger.info("workgroup org : " + deptBean.toString());
   /* ORGBean deptBean = null;
    deptBean = new ORGBean("", "", "", null, "", "", "");*/
    
    CompanyBean companyBean = (CompanyBean) paramMap.get("companyBean");
   // System.out.println(companyBean.toString());
    if(companyBean == null) {
      companyBean = new CompanyBean("", "");
    }
    
    String useFlay = (String) paramMap.get("useFlay");
    if(useFlay == null) {
      useFlay = "0";
    }
    String rateValue = (String) paramMap.get("rateValue");
    if(rateValue == null) {
      rateValue = "";
    }
    AccountGroupWork groupWork = new AccountGroupWork();
    groupWork.save(groupType, groupBaseBean, useFlay, companyBean, categoryBean, deptBean, rateValue);
    if(groupWork.status) {
      status = true;
    }else {
      status = false;
      remark = groupWork.getRemark();
    }
  }

  @Override
  public boolean getStatus() {
    // TODO Auto-generated method stub
    return status;
  }

  @Override
  public String getRemark() {
    // TODO Auto-generated method stub
    return remark;
  }

}
